package com.clannad.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.clannad.eduservice.entity.EduVideo;
import com.clannad.eduservice.feign.VodClient;
import com.clannad.eduservice.mapper.EduVideoMapper;
import com.clannad.eduservice.service.EduVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author clannad
 * @since 2022-08-11
 */
@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo> implements EduVideoService {

    @Autowired
    VodClient vodClient;
    @Override
    public void removeVideoByCourseId(String courseId) {

        LambdaQueryWrapper<EduVideo> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EduVideo::getCourseId,courseId);
        //更具id查出所有的视频id
        List<EduVideo> list = this.list(lambdaQueryWrapper);
        List<String> collect = list.stream().map(item -> {
            String videoSourceId = item.getVideoSourceId();
            return videoSourceId;
        }).collect(Collectors.toList());
        if(collect.size()>0){
            vodClient.deleteBatch(collect);
        }
        System.out.println(622);
        this.remove(lambdaQueryWrapper);
    }
}
